<link rel="stylesheet" type="text/css" href="__PUBLIC__/AdminLTE/plugins/bootstrap-fileinput/css/fileinput.css" />
<div class="content-wrapper">
    <section class="content-header">
        <h1>客户详情</h1>
        <ol class="breadcrumb">
            <li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">客户管理</li>
            <li class="active">客户详情</li>
            <li class="active">下单</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="container-fluid">
                <div class="col-md-5">
                    <div class="box box-widget widget-user-2">
                        <!-- Add the bg color to the header using any of the bg-* classes -->
                        <if condition="$customer.gender eq 1 ">
                            <div class="widget-user-header bg-aqua-active">
                                <div class="widget-user-image">
                                    <img class="img-circle" src="__PUBLIC__/AdminLTE/dist/img/avatar5.png" alt="User Avatar">
                                </div>
                                <!-- /.widget-user-image -->
                                <h3 class="widget-user-username">{$customer.name} <span class="pull-right badge bg-red-gradient">{$customer.gender_desc}</span></h3>
                                <h5 class="widget-user-desc">{$customer.company_name}</h5>
                            </div>
                            <else />
                            <div class="widget-user-header bg-purple-active">
                                <div class="widget-user-image">
                                    <img class="img-circle" src="__PUBLIC__/AdminLTE/dist/img/avatar2.png" alt="User Avatar">
                                </div>
                                <!-- /.widget-user-image -->
                                <h3 class="widget-user-username">{$customer.name} <span class="pull-right badge bg-red-gradient">{$customer.gender_desc}</span></h3>
                                <h5 class="widget-user-desc">{$customer.company_name}</h5>
                            </div>
                        </if>

                        <div class="box-footer no-padding">
                            <ul class="nav nav-stacked">
                                <li><a href="#">客户级别 <span class="pull-right badge bg-blue">{$customer.level_desc}</span></a></li>
                                <li><a href="#">客户类别 <span class="pull-right badge bg-aqua">{$customer.type_desc}</span></a></li>
                                <li><a href="#">推广产品&游戏 <span class="pull-right badge bg-green">{$customer.product_name}</span></a></li>
                                <li><a href="#">手机号 <span class="pull-right badge bg-purple">{$customer.mobile}</span></a></li>
                                <li><a href="#">固话 <span class="pull-right badge bg-info">{$customer.tel}</span></a></li>
                                <li><a href="#">微信 <span class="pull-right badge bg-green-active">{$customer.wechat}</span></a></li>
                                <li><a href="#">QQ <span class="pull-right badge bg-red">{$customer.qq}</span></a></li>
                                <li><a href="#">产品一级名称 <span class="pull-right badge bg-blue-active">{$customer.first_name}</span></a></li>
                                <li><a href="#">产品二级名称 <span class="pull-right badge bg-blue-active">{$customer.second_name}</span></a></li>
                                <li><a href="#">客户阶段 <span class="pull-right badge bg-black-active">{$customer.phase_desc}</span></a></li>
                                <li><a href="#">客户资质
                                    <if condition="$customer.upfile neq ''">
                                        <span class="pull-right badge bg-info" style="cursor: pointer" onclick="window.location.href='/admin/index/downloadFile?file={$customer.upfile|urlencode}'"><i class="fa fa-cloud-download"></i>下载</span>
                                        <else />
                                        <span class="pull-right badge bg-black-active">未上传</span>
                                    </if>
                                </a></li>
                                <li><a href="#">是否下单 <span class="pull-right badge bg-black-active">
                                    <if condition="$customer.is_order eq 1">
                                        已下单
                                        <else />
                                        未下单
                                    </if>
                                </span></a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="col-md-5">
                    <!-- 添加产品 -->
                    <div class="box box-info">
                        <div class="box-header with-border">
                            客户操作
                        </div>
                        <div class="box-body">
                            <button class="btn btn-warning btn-md" type="button" onclick="window.location.href='/admin/customer/editCustomer?id={$customer.id}'">修改</button>&nbsp;
                            <button class="btn btn-info btn-md update_customer" type="button" data-toggle="modal" data-target="#myModal" data-phase="{$customer.phase}" data-id="{$customer.id}">更新</button>&nbsp;
                            <button class="btn btn-primary btn-md" type="button" onclick="window.location.href='/admin/customer/customerFollow?id={$customer.id}'">跟进</button>&nbsp;
                            <button class="btn btn-primary btn-md btn-add-order" type="button" data-id="{$customer.id}" data-oid="{$customer.order_id}">下单</button>&nbsp;
                            <button type="button" class="btn btn-md btn-success btn-upload" onclick="return showModal('{$customer.id}')" data-toggle="modal" data-target="#exampleModal"><i class="fa fa-cloud-upload"></i>上传</button>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </section>
</div>
<!--更新-->
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="margin-top: 200px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">阶段更新</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form" action="javascrip:;" method="post">
                    <div class="form-group">
                        <input type="hidden" name="customer_id" id="customer_id">
                        <input type="hidden" name="old_phase" id="old_phase">
                    </div>
                    <div class="form-group">
                        <label for="u_phase" class="control-label col-sm-4">客户阶段 </label>
                        <div class="col-sm-6">
                            <select name="u_phase" id="u_phase" class="form-control">
                                <php>unset($phaseList['20']);</php>
                                <foreach name="phaseList" item="s_val" key="s_key">
                                    <option value="{$s_key}">{$s_val}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="update">确认</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<!-- Modal1 -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">文件上传</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form id="upload-form" method="post" action="javascript:;" role="form" class="form-horizontal" enctype="multipart/form-data">
                    <input type="hidden" id="up_customer_id" name="up_customer_id" value="">
                    <div class="file-loading">
                        <input id="import" name="import[]" type="file" multiple>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<script src="__PUBLIC__/AdminLTE/plugins/bootstrap-fileinput/js/fileinput.min.js"></script>
<script src="__PUBLIC__/AdminLTE/plugins/bootstrap-fileinput/js/plugins/purify.js"></script>
<script src="__PUBLIC__/AdminLTE/plugins/bootstrap-fileinput/js/plugins/sortable.js"></script>
<script src="__PUBLIC__/AdminLTE/plugins/bootstrap-fileinput/js/plugins/piexif.js"></script>
<script src="__PUBLIC__/AdminLTE/plugins/layer/layer.js"></script>
<script src="__PUBLIC__/AdminLTE/plugins/bootstrap-fileinput/js/locales/zh.js"></script>
<script type="application/javascript">
    var p1Json = {$p1|json_encode};
    var p2Json = {$p2|json_encode};
    $(document).on('ready', function() {
        $("#import").fileinput({
            showUpload: false,
            language: "zh",
            layoutTemplates: {
                main1: "{preview}\n" +
                "<div class=\'input-group {class}\'>\n" +
                "   <div class=\'input-group-btn\ input-group-prepend'>\n" +
                "       {browse}\n" +
                "       {upload}\n" +
                "       {remove}\n" +
                "   </div>\n" +
                "   {caption}\n" +
                "</div>"
            },
            // 需要展示的图片设置，比如图片的宽度等
            initialPreviewAsData: true,

            deleteUrl: "/admin/customer/ajaxDeleteFile",
            overwriteInitial: false,
            initialPreview: p1Json,
            initialPreviewConfig : p2Json,
            // 是否展示预览图
            uploadAsync : true,
            // 最少上传的文件个数限制
            minFileCount : 1,
            // 最多上传的文件个数限制
            maxFileCount : 10,
            // 是否显示移除按钮，指input上面的移除按钮，非具体图片上的移除按钮
            showRemove : true,
            //是否显示[选择]按钮,指input上面的[选择]按钮,非具体图片上的上传按钮
            showBrowse : true,
            // 展示图片区域是否可点击选择多文件
            browseOnZoneClick : true,
            // 如果要设置具体图片上的移除、上传和展示按钮，需要设置该选项
            allowedFileExtensions: ['png','jpg','jpeg','zip','rar','7z','xls','xlsx','doc','docx'],
            uploadUrl: '/admin/customer/ajaxUploadQualification',
            uploadExtraData : {customer_id:"{$customer.id}"},
            previewFileIcon: '<i class="fa fa-file"></i>',
        });
    });
    function showModal(oit_id) {
        $("#up_customer_id").val(oit_id);
    }
    $(function () {
        //更新阶段
        $(".update_customer").click(function(){
            var customer_id = $(this).attr('data-id');
            var phase = $(this).attr('data-phase');
            $('#customer_id').val(customer_id);
            $('#u_phase').val(phase);
            $('#old_phase').val(phase);
        });
        //更新阶段
        $('#update').click(function () {
            var customer_id = $('#customer_id').val();
            var phase = $('#u_phase').val();
            var old_phase = $('#old_phase').val();

            if(customer_id == ''){
                layer.msg('参数错误',{time:1000});
                return false;
            }
            if(parseInt(phase)<parseInt(old_phase) && phase!=-5){
                layer.msg('更新阶段必须大于当前阶段',{time:1000});
                return false;
            }
            if(!phase){
                layer.msg('请选择阶段',{time:1000});
                return false;
            }

            $.post('/admin/customer/updateCustomerPhase',{
                customer_id:customer_id,
                phase:phase
            },function(_data) {
                $('#myModal').modal('hide');
                if(_data.Code == 999) {
                    ArtDialogHlp.showInfo('提示', '操作成功', function(){
                        window.location.reload(true);
                    });
                } else {
                    ArtDialogHlp.showInfo('提示', _data.Msg);
                }
            },'JSON');
        });
        //开单
        $('.btn-add-order').click(function () {
            var customer_id = $(this).attr('data-id');
            var order_id = $(this).attr('data-oid');

            if(customer_id == ''){
                ArtDialogHlp.showInfo('提示', '参数错误');
                return false;
            }

            $.post("/admin/customer/ajaxGetOrderInfo", {
                customer_id:customer_id,
                order_id:order_id
            }, function(_data) {
                if(_data.Code == 999) {
                    window.location.href = '/admin/customer/editOrder?order_id='+ _data.Data.orderInfo.id;
                } else {
                    ArtDialogHlp.showInfo('提示', _data.Msg);
                }
            },'json');
        });
    })
</script>